﻿			$(function() {
				$("#tabs").tabs();
			});
			
			$(function() {
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
		var name = $( "#name" ),
			email = $( "#email" ),
			password = $( "#password" ),
			allFields = $( [] ).add( name ).add( email ).add( password ),
			tips = $( ".validateTips" );

		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
		
		$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#editDialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#ELinhVucDialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#ENganhNgheDialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#ENhaTuyenDung-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#EDonDangTuyen-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#CLinhVucdialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#CNganhNghedialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});

		$( "#create-user" )
			.button()
			.click(function() {
				$( "#dialog-form" ).dialog( "open" );
			});
			
		$(".EditUser")
			.click(function(){
				$( "#editDialog-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				
				$("#eid").get(0).value = $str_id;
				
			});
			
		$(".EditLinhVuc")
			.click(function(){
				$( "#ELinhVucDialog-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				$("#eLVid").get(0).value = $str_id;
				
			});
			
		$(".EditNganhNghe")
			.click(function(){
				
				$( "#ENganhNgheDialog-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				
				var $str_lvid = $(this).attr('v3');
				
				$("#eNNid").get(0).value = $str_id;
				$("#eLV_NNid").get(0).value = $str_lvid;
				
			});
	
		$(".EditNhaTuyenDung")
			.click(function(){
				$( "#ENhaTuyenDung-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				
				
				$("#eNTDid").get(0).value = $str_id;
				
				
				
			});
			
		$(".EditDonDangTuyen")
			.click(function(){
				$( "#EDonDangTuyen-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				$("#eDDTid").get(0).value = $str_id;
				});
			
		$("#create-linhvuc")
			.button()
			.click(function() {
				$( "#CLinhVucdialog-form" ).dialog( "open" );
			});
			
		$("#create-nganhnghe")
			.button()
			.click(function() {
				$( "#CNganhNghedialog-form" ).dialog( "open" );
			});
		
		
		$("button").button();
	
	});
	
		$(function(){ 
			$("#Create").validationEngine('attach'); 
		});	
	function InstallFunction(name) {
		server[name] = function() { AE_CallRemote(name, arguments); }
	}
		server = {};
		InstallFunction("Select");

function onSelectSuccess(response) {
	jsonData = eval('(' + response + ')');
	//alert(jsonData[0].TenNganhNghe);
	
	$("#tnganhnghe").html('<table id="nganhnghe" class="ui-widget ui-widget-content">'+
	'<thead>'+
	'<tr class="ui-widget-header ">'+
	'<th>Tên Ngành Nghề</th>'+
	'<th>Tên Lĩnh Vực</th>'+
	'<th>Trạng Thái</th>'+
	'<th>Sửa</th>'+
	'</tr>'+
	'</thead>'+
	'<tbody>'+
	'</tbody>'+
	'</table>'
	
	)
	
	for (var i=0; i<jsonData.length; i++) {
		if(jsonData[i].HoatDong == 1)
		{
			$("#nganhnghe tbody" ).after('<tr>'+
				'<td>'+ jsonData[i].TenNganhNghe + '</td>'+
				'<td>'+ jsonData[i].TenLinhVuc + '</td>'+
				'<td> Hoạt Động </td>'+
				'<td><button class="EditNganhNghe" v1="' + jsonData[i].NganhNgheID +'" v2="'+jsonData[i].TenNganhNghe+'">Sửa</button>'+
				'</tr>'
			);
		}
		else
		{
			$("#nganhnghe tbody" ).after('<tr>'+
				'<td>'+ jsonData[i].TenNganhNghe + '</td>'+
				'<td>'+ jsonData[i].TenLinhVuc + '</td>'+
				'<td> Chưa hoạt động </td>'+
				'<td><button class="EditNganhNghe" v1="' + jsonData[i].NganhNgheID +'" v2="'+jsonData[i].TenNganhNghe+'">Sửa</button>'+
				'</tr>'
			);
		}
	}
	$("button").button();
	
		$( "#ENganhNgheDialog-form" ).dialog({
			autoOpen: false,
			height: 300,
			width: 350,
			modal: true,
			
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
			$(".EditNganhNghe")
			.click(function(){
				
				$( "#ENganhNgheDialog-form" ).dialog( "open" );
				var $str_id = $(this).attr('v1');
				
				var $str_lvid = $(this).attr('v3');
				
				$("#eNNid").get(0).value = $str_id;
				$("#eLV_NNid").get(0).value = $str_lvid;
				
			});
		
	
} 
function doSelect(){
	
	var w = document.LV.ddlLinhVuc.selectedIndex;
	var selected_value = document.LV.ddlLinhVuc.options[w].value;
	//alert(selected_value);
	$('#nganhnghe').remove();
	
	
	server.Select(selected_value,onSelectSuccess);
	
}
function clearTable()
{
	var tableRef = document.getElementById('nganhnghe');
	while ( tableRef.rows.length > 0 )
	{
		tableRef.deleteRow(0);
	}
}


